import json
import chardet
import jsonpath

# 1.json.dumps() : 将python数据结构转为Json数据
pylist = [1, 2, 3, 4]
pytuple = (1, 2, 3, 4)
pydict = {"city": "北京", "name": "大猫"}

json1 = json.dumps(pylist)            
json2 = json.dumps(pytuple)
json3 = json.dumps(pydict)                        # {"name": "\u5927\u732b", "city": "\u5317\u4eac"}
json4 = json.dumps(pydict, ensure_ascii=False)    # {"name": "大猫", "city": "北京"}--->开发用这种utf8


# 2. json.load(file) : 将Json文件转为python数据结构
list1 = json.load(open("listStr.json"))

# 2. json.loads(str) : 将json
listStr = open("listStr.json").read()
list2 = json.loads(listStr)


# 3. jsonpath之于json, 类似xpath之于html
# 参见gitbook的爬虫--2.7.JSON模块于JsonPath